# coding:utf-8
from contextlib import nullcontext
import re
import json
from PyQt6.QtCore import Qt, QEasingCurve, QUrl
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QWidget, QVBoxLayout
from qfluentwidgets import (SingleDirectionScrollArea, SmoothScrollArea, ToolTipFilter, PixmapLabel,
                            ScrollArea, ImageLabel, HorizontalPipsPager, PipsScrollButtonDisplayMode, VerticalPipsPager)
from qframelesswindow.webengine import FramelessWebEngineView

from views.template_chat_view import BaseInfoTemplateView
from .base_gallery_view import GalleryInterface
from .common.translator import Translator
from common.utils.JsonReplace import JsonPlaceholderReplacer


class StockRiskView(BaseInfoTemplateView):
    """ Scroll interface """

    def __init__(self,   parent=None):
        t = Translator()
        super().__init__(
            "StockRiskView",
            parent=parent
        )

        # 添加一个报表
        self.addEcahtMainView("stock_risk")

    def doSearch(self):
        AntLogger.info(f"查询股票{self.searchKey}")
        self.updateEchatData()

    def getEchatData(self, jsonData: dict):
        if self.searchKey is not None and self.searchKey != "":
            AntLogger.info(f"校验通过{self.searchKey}")
            source_data = [
                {"value": 40, "name": "连续涨停"},
                {"value": 38, "name": "股价过高"},
                {"value": 32, "name": "呈连续下跌趋势"},
                {"value": 30, "name": "成家额下降大量卖出"},
                {"value": 28, "name": "节前风险时段"},
                {"value": 26, "name": "已盈利20以上"},
                {"value": 22, "name": "财报周期"},
                {"value": 18, "name": "股价新高"}
            ]

            replacer = JsonPlaceholderReplacer(jsonData)
            replacer.replace_placeholder("__STOCK_DATA__", source_data)
            
            AntLogger.info(f"最终解析对象{replacer.get_modified_json()}")
            return replacer.get_modified_json()
        else:
            return jsonData
